package com.heqiang.hystrix;

import com.netflix.hystrix.HystrixCommand;
import org.springframework.web.client.RestTemplate;

public class MyHystrixCommand extends HystrixCommand<String> {

    private RestTemplate restTemplate;

    //写一个构造方法
    public MyHystrixCommand(Setter setter, RestTemplate restTemplate) {
        super(setter);
        this.restTemplate = restTemplate;
    }

    @Override
    protected String run() throws Exception {
        String s = restTemplate.getForObject("http://SPRINGCLOUD-SEVER-PROVIDER/admin/get", String.class);
        return s;
    }

    @Override
    public String getFallback() {
        return "实现服务熔断/降级处理";
    }
}
